package caidan.data;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class Flavour
{
	static String[] flavourStrings = {"未选择", "味精", "醋", "花椒", "胡椒", "胡椒粉",
			"干辣椒", "白糖", "生姜", "酱油", "孜然", "八角", "料酒", "苏打粉", "豆瓣酱", "番茄酱",
			"辣根", "芥末", "草寇", "冰糖", "山葵", "红糖", "咖喱", "茴香籽", "花生油", "猪油",
			"亚麻籽油", "葡萄籽油", "蚝油", "茶油", "芝麻油", "椰子油", "胡麻油"};
	public static Flavour unChooseFlavour = new Flavour();
	static Flavour[] flavours = new Flavour[flavourStrings.length];

	private short data;
	private String name;
	private int totalQuality;

	Flavour()
	{
	}

	Flavour(short data, String name)
	{
		this.data = data;
		this.name = name;
	}

	public short getData()
	{
		return data;
	}

	public String getName()
	{
		return name;
	}

	public void addQuality(int quality)
	{
		totalQuality += quality;
	}

	public void resetQuality()
	{
		totalQuality = 0;
	}

	public int getQuality()
	{
		return totalQuality;
	}

	public static Flavour getFlavour(short data)
	{
		if (data <= 0 || data >= flavours.length)
			return unChooseFlavour;
		if (flavours[data] == null)
			flavours[data] = new Flavour(data, flavourStrings[data]);
		return flavours[data];
	}

	void writeData(DataOutputStream dos) throws IOException
	{
		dos.writeShort(data);
	}

	static Flavour readData(DataInputStream dis, int appVersion)
			throws IOException
	{
		return getFlavour(dis.readShort());
	}
}
